package com.sample.action;
/**
 * 行政区域action
 */
import com.sample.action.form.AreaForm;
import com.sample.javabean.Area;
import com.sample.util.Pager;

public class AreaAction extends BaseAction{
	private Area area = new Area();
	private AreaForm areaForm = new AreaForm();
	private String area_no;
	private Pager<Area> pageList;
	
	//构造函数
	public AreaAction(Area area, AreaForm areaForm, String area_no) {
		super();
		this.area = area;
		this.areaForm = areaForm;
		this.area_no = area_no;
	}
	public AreaAction() {
		super();
	}
	
	/**
	 * 添加行政区域
	 * @return
	 */
	public String inputArea(){
		return "inputArea";
	}
	public String addArea()throws Exception{
		try{
			if(areaForm!=null){
				area.addArea(areaForm);
			}
			return SUCCESS;
		}catch (Exception e) {
			
			e.printStackTrace();
			throw new Exception("添加行政区域信息失败！Exception_action:<--"+e+"-->"); 
		}
	}
	
	/**
	 * 删除行政区域
	 * @return
	 * @throws Exception
	 */
	public String delArea()throws Exception{
		try{
			if(areaForm!=null){
				area.setArea_no(area_no);
				area.delArea();
			}
			return SUCCESS;
		}catch (Exception e) {
			e.printStackTrace();
			throw new Exception("删除行政区域信息失败！Exception_action:<--"+e+"-->"); 
		}	
		
	}
	
	/**
	 * 编辑行政区域信息
	 * @return
	 * @throws Exception
	 */
	public String editArea()throws Exception{
		try{
			area.setArea_no(area_no);
			area.load();
			return "editArea";
		}catch (Exception e) {
			e.printStackTrace();
			throw new Exception("加载行政区域信息失败！Exception_action:<--"+e+"-->"); 
		}	
	}
	
	public String edit()throws Exception{
		try{
			if(areaForm!=null){
				LOG.info("bull?"+areaForm.getArea_level());
			area.editArea(areaForm);
			}
			return SUCCESS;
		}catch (Exception e) {
			e.printStackTrace();
			throw new Exception("编辑行政区域信息失败！Exception_action:<--"+e+"-->"); 
		}	
	}
	
	/**
	 * 分页显示
	 * @return
	 * @throws Exception
	 */
	public String listArea()throws Exception{
		try{
			pageList=area.list(page, size,areaForm);
			return "listArea";
		}catch (Exception e) {
			e.printStackTrace();
			throw new Exception("分页显示失败，Exception_Action:"+e);
		}
	}
	
	
	
	//属性定义方法get、set方法
	public Area getArea() {
		return area;
	}
	public void setArea(Area area) {
		this.area = area;
	}
	public AreaForm getAreaForm() {
		return areaForm;
	}
	public void setAreaForm(AreaForm areaForm) {
		this.areaForm = areaForm;
	}
	public String getArea_no() {
		return area_no;
	}
	public void setArea_no(String area_no) {
		this.area_no = area_no;
	}
	public Pager<Area> getPageList() {
		return pageList;
	}
	public void setPageList(Pager<Area> pageList) {
		this.pageList = pageList;
	}
	
	

}